<% include head.ejs%>
<body>
<div class="wp">
    <header class="t-header">
        <div class="topbar">
            <a href="/order/payOrder" class="gobakA fl">
                <i class="icon-angle-left"></i>
            </a>
            <span>收货地址管理</span>
        </div><!-- topbar end -->
    </header>

    <% for (var i in addressInfo){%>
    <div class="shAddsBody mt20">
        <div id="<%= addressInfo[i].addr_id%>" class="shadsbox pr">
            <div class="user">
                收货人：<span class="name"><%= addressInfo[i].receiver%></span>，<span class="phone"><%= addressInfo[i].receiver_tel%></span>
            </div>
            <div class="adds">
                收货地址：<span class="dz"><%= addressInfo[i].province+addressInfo[i].city+addressInfo[i].county+addressInfo[i].detail%></span>
            </div>
        </div>
        <div class="editAds clearfix">
            <% if (addressInfo[i].isdefault == 1){%>
            <span class="deAds">默认地址</span>
            <%}else{%>
            <span onclick="setDefault(<%= addressInfo[i].addr_id%>)" class="chkbody">
                    <input class="chkInput"  type="checkbox">
                    <label class="chkInputLb" for="adsDe1"></label>
                </span>
            <span>默认地址</span>
            <%}%>
            <span id="<%= addressInfo[i].addr_id%>" class="del">删除</span>
            <!--<span id="" class="edit">编辑</span>-->
        </div>
    </div>
    <%}%>

    <div class="addBtn">
        <a class="addADSa" href="#"><i class="icon-plus"></i> 添加收货地址</a>
    </div>

    <div class="popAddads">
        <div class="adsBox">
            <div class="tit">添加收货地址</div>
            <div class="lxinfo clearfix">
                <li>
                    <input class="name" id="name" value="" placeholder="名字">
                </li>
                <li>
                    <input class="tel" id="tel" value="" placeholder="电话">
                </li>
            </div>
            <div class="adsCity">
                <div id="city_sel" class="clearfix">
                    <div class="m_zlxg" id="shenfen">
                        <p title="">选择省份</p>
                        <div class="m_zlxg2">
                            <ul></ul>
                        </div>
                    </div>
                    <div class="m_zlxg" id="chengshi">
                        <p title="">选择城市</p>
                        <div class="m_zlxg2">
                            <ul></ul>
                        </div>
                    </div>
                    <div class="m_zlxg" id="quyu">
                        <p title="">选择区域</p>
                        <div class="m_zlxg2">
                            <ul></ul>
                        </div>
                    </div>
                    <input id="sfdq_num" type="hidden" value="" />
                    <input id="csdq_num" type="hidden" value="" />
                    <input id="sfdq_tj" type="hidden" value="" />
                    <input id="csdq_tj" type="hidden" value="" />
                    <input id="qydq_tj" type="hidden" value="" />
                </div>
            </div>
            <div class="jdInfos">
                <input id="jdinfo" name="jdinfo" value="" placeholder="请填写详细街道地址">
            </div>
            <div class="defshads clearfix">
                    <span class="chkbody">
                        <input class="chkInput" id="adsDe3" type="checkbox">
                        <label class="chkInputLb" for="adsDe3"></label>
                    </span>
                <span>默认收货地址</span>　
            </div>
            <a href="#" class="saveAdsnew">保存</a>
        </div>
    </div>


</div>

<script type="text/javascript">
    $(function(){

        $("#city_sel").sjld("#shenfen","#chengshi","#quyu");

        $(".shadsbox.pr").click(function () {
            location.href = "/order/payOrder?addrId="+$(this).attr("id");
        });

        $(".del").click(function () {
            $.get('/order/delAddr',{addrId:$(this).attr("id")},function (data) {
                var restr = JSON.parse(data);
                if(restr.code == 0){
                    alert('删除成功');
                }else {
                    alert(restr.msg);
                }
                location.reload();
            })
        });

        $('.saveAdsnew').click(function () {
            var param = {
                province:$('#sfdq_tj').val(),
                city:$('#csdq_tj').val(),
                county:$('#qydq_tj').val(),
                detail:$('#jdinfo').val(),
                receiver:$('#name').val(),
                receiver_tel:$('#tel').val(),
                isdefault:$('#adsDe3').is(':checked')?1:0
            }
            $.get('/order/addAddr',param,function (data) {
                var restr = JSON.parse(data);
                if(restr.code == 0){
                    alert('添加成功');
                }else {
                    alert(restr.msg);
                }
                location.reload();
            })
        });

        $('.edit')
    });

    function setDefault(addrId) {
        $.get('/order/setAddrDef',{addrId:addrId},function (data) {
            var restr = JSON.parse(data);
            if(restr.code == 0){
                alert('修改成功');
            }else {
                alert(restr.msg);
            }
            location.reload();
        })
    }
</script>
</body>
</html>